<%@page import="org.apache.struts.util.RequestUtils"%>
<%@page import="org.apache.commons.lang.StringUtils"%>
<%@page import="org.brickred.socialauth.AuthProvider"%>
<%@page import="org.brickred.socialauth.util.SocialAuthUtil"%>
<%@page import="java.util.Map"%>
<%@page import="org.brickred.socialauth.Profile"%>
<%@page import="java.util.ArrayList"%>
<%@page import="org.brickred.socialauth.Contact"%>
<%@page import="java.util.List"%>
<%@page import="java.io.InputStream"%>
<%@page import="org.brickred.socialauth.SocialAuthConfig"%>
<%@page import="org.brickred.socialauth.SocialAuthManager"%>
<%@page import="org.apache.struts.action.ActionForward"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
	
%>
<%

	
			// TODO Auto-generated method stub
			try{
			
			String id = request.getParameter("id");
			out.println(id);
				if(id!=null && id.equalsIgnoreCase("gmail")){
					id="google";
					session.setAttribute("service","Gmail");
				}else if(id!=null && id.equalsIgnoreCase("yahoo")){
					session.setAttribute("service","Yahoo");
				}
				SocialAuthManager manager = null;
				
				if(session.getAttribute("manager")!=null){
					manager = (SocialAuthManager) session.getAttribute("manager");	
				}else{
					manager = new SocialAuthManager();	
				}
				
				
				SocialAuthConfig conf = SocialAuthConfig.getDefault();
				//InputStream in = Social.class.getClassLoader().getResourceAsStream("oauth_consumer.properties");
				//System.out.println("in " + in);
				conf.load("oauth_consumer.properties");
				manager = new SocialAuthManager();
				manager.setSocialAuthConfig(conf);
				//HttpServletRequest request = null;
				//String returnToUrl = RequestUtils.absoluteURL(request,"/socialAuthSuccessAction.do").toString();
				
				String returnToUrl = RequestUtils.absoluteURL(request,"/printContacts.jsp").toString();
				//String id = "google";
				//String id = "yahoo";
				
				String acno = request.getParameter("acno");
				session.setAttribute("acno", acno);
				//System.out.println(id + " \n " + returnToUrl);
				String url = manager.getAuthenticationUrl(id, returnToUrl);
				System.out.println("Older SocialAuth:---" + manager);
				if(url!=null){
					session.setAttribute("manager",manager);
					response.sendRedirect(url);
				}
				
			
			}catch(Exception e){
				e.printStackTrace();
			}
		


%>
</body>
</html>